package com.baizhi.service.impl;

import com.baizhi.dao.mongo.CommentDao;
import com.baizhi.domain.dto.CommentSaveDto;
import com.baizhi.domain.mongo.Comment;
import com.baizhi.service.CommentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentDao commentDao;

    // 添加评论
    @Override
    public void saveComment(CommentSaveDto param) {
        Comment comment = new Comment();
        BeanUtils.copyProperties(param, comment);
        comment.setCid(UUID.randomUUID().toString());
        commentDao.save(comment);
    }

    // 删除评论
    @Override
    public void deleteByCid(String cid) {
        commentDao.deleteById(cid);
    }

    // 根据文章id查询评论
    @Override
    public List<Comment> findCommentsByAid(Integer aid) {
        return commentDao.findByAid(aid);
    }
}
